from django.shortcuts import render,redirect
#导包
from django.http import HttpResponse,HttpResponseRedirect,JsonResponse
#导入类视图

from django.views import View
from rest_framework.response import Response
from rest_framework.views import APIView
# Create your views here.
from functools import wraps
from django.utils.decorators import method_decorator
from .serve import *
from django.db.models import Q
import re
#导入时间模块
import time
from django_test.settings import UPLOAD_ROOT
import os
#导入dwebsocket的库
from dwebsocket.decorators import accept_websocket
import uuid

from django.core import paginator


class MdLogin(APIView):
    def post(self, request):
        username = request.data['username']
        password = request.data['password']
        users = MdUser.objects.filter(username=username, password=password).first()
        if users:
            return Response({
                'code': 200,
                'data': users.id
            })

        else:
            return Response({
                'code': 400
            })


class AllGoodsInfo(APIView):
    def post(self,request):
        good = GoodsInfo.objects.all()

        good_ser = GoodsInfoSer(good,many=True)

        return Response({
            'code': 200,
            'data': good_ser.data
        })


# 评论
class AddComment(APIView):
    def post(self,request):

        comment = CommentSer(data=request.data)
        if comment.is_valid():

            comment.save()

        return Response({
            'code':200,

        })


class CommentList(APIView):
    def get(self,request):

        comments = Comment.objects.all()

        comment_ser = CommentSer(comments,many=True)

        return Response({
            'data': comment_ser.data
        })











